<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>服务接口管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"

          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script type="text/javascript"
            src="../lib/vue/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <script type="text/javascript" src="../js/global.js"></script>
    <script type="text/javascript" src="../js/store.js"></script>
    <script type="text/javascript" src="../js/cookies.js"></script>
    <script src="../lib/vue/vue.min.js"></script>
    <script src="../lib/vue/axios.min.js"></script>

</head>

<body>
<div class="x-body layui-anim layui-anim-up">
    <form class="layui-form">

        <div class="layui-form-item" hidden>
            <div class="layui-input-inline">
                <input type="text" id="L_CompanyId" name="id" required=""
                       lay-verify=""
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_companyName" class="layui-form-label">
                <span class="x-red">*</span>公司名称
            </label>
            <div class="layui-input-inline" style="width: 300px;">
                <input type="text" id="L_companyName" name="name" required=""
                       lay-verify="companyName"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>非空且唯一
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="edit" lay-submit="">
                保存
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
            $ = layui.jquery
            var form = layui.form
                , layer = layui.layer
            //获取选中的数据 进行格式转换，并加载到form表单中
            var editData = parent.$("#editCompany").val();
            var editArray = JSON.parse(editData)
            $('#L_CompanyId').val(editArray.id)
            $('#L_companyName').val(editArray.name)
            form.render();//下拉菜单渲染 把内容加载进去
            //自定义验证规则
            form.verify({
                companyName: function (value) {
                    if (value.length < 1) {
                        return '环境名称不可为空'
                    }
                },
            })

            //监听提交
            form.on('submit(edit)', function (data) {
                $.putForm(_hostUrl + "/company", data.field, function (res) {
                    if (res.responseCode === 201) {
                        layer.msg('修改成功', {
                            icon: 1,
                            time: 500
                        }, function () {
                            x_admin_close();
                            var table = parent.window.layui.table;
                            table.reload('companyList')
                        });
                    } else {
                        layer.msg(res.responseMsg, {icon: 2, time: 1500})
                    }
                })
                return false
            })

        }
    )
</script>
</body>

</html>